package com.cvr.project.repertory;

import android.annotation.SuppressLint;

import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;

/**
 * _ooOoo_
 * o8888888o
 * 88" . "88
 * (| -_- |)
 * O\ = /O
 * ____/`---'\____
 * .   ' \\| |// `.
 * / \\||| : |||// \
 * / _||||| -:- |||||- \
 * | | \\\ - /// | |
 * | \_| ''\---/'' | |
 * \ .-\__ `-` ___/-. /
 * ___`. .' /--.--\ `. . __
 * ."" '< `.___\_<|>_/___.' >'"".
 * | | : `- \`.;`\ _ /`;.`/ - ` : | |
 * \ \ `-. \_ __\ /__ _/ .-` / /
 * ======`-.____`-.___\_____/___.-`____.-'======
 * `=---='
 * .............................................
 * 佛祖保佑             永无BUG
 *
 * @author :created by master
 * time :2021-6-29 21:58:05
 * 描述：BaseRepository
 */
public class BaseRepository {
    /**
     * @param flowable
     * @param <T>
     * @return
     */
    public <T> BaseSubscriber<T> request(Flowable<BaseResponse<T>> flowable) {
        BaseSubscriber<T> baseSubscriber = new BaseSubscriber<>();
        flowable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(baseSubscriber);
        return baseSubscriber;
    }

    /**
     * @param flowable
     * @return
     */
    @SuppressLint("CheckResult")
    public Observable<ResponseBody> request(Observable<ResponseBody> flowable) {
        return flowable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
    }
}
